#!/usr/bin/env groovy
// @file     SigninRecord.groovy
// @purpose  represents a single signin record
// @author   Mac Radigan  

package ycoa.scan.signin

import ycoa.archive.*

public class SigninRecord { 
  // record globals
  public String reportID
  public int classReportID
  public String className
  public Date classDate
  public String formPath
  public String formName
  public String barcode
  // local fields
  public int studentID
  public String studentName
  public String feeType
  public String parentName
  public boolean signature
  public boolean present
  public boolean makeup1
  public boolean makeup2
  public boolean makeup3
  public boolean specialty
  public boolean evaluation
  public boolean amountPaid
  public int getMakeups() {
    int makeupCount = 0
    if(makeup1) makeupCount++
    if(makeup2) makeupCount++
    if(makeup3) makeupCount++
    return makeupCount
  }
  public String getURL() {
    String url =  "/service.asp"
    url += "?module=Scan"
    url += "&sproc=yy_scan_UpdateClassRoster"
    url += "&ClassReportID=${this.classReportID}"
    url += "&StudentID=${this.studentID}"
    if(this.signature)  { url += "&Signature=1" }  else { url += "&Signature=0" }
    if(this.signature)  { url += "&Payment=1" }    else { url += "&Payment=0" }
    if(this.present)    { url += "&Present=1" }    else { url += "&Present=0" }
    url += "&Makeups=${this.getMakeups()}"
    if(this.evaluation) { url += "&Evaluation=1" } else { url += "&Evaluation=0" }
    if(this.specialty)  { url += "&Specialty=1" }  else { url += "&Specialty=0" }
    return url
  }
  public String getLogHeader() {
    def newLine = System.getProperty("line.separator")
    def archive = new Archive(null, null)
    def stamp = archive.getUniqueTimeStamp() 
    def sb = new StringBuffer()
    sb.append("LOG DATE:  ${stamp}")
    sb.append(newLine)
    sb.append("CPID#      STID#     PRESENT  MU#  SPECIAL  EVALUATION")
    sb.append(newLine)
    sb.append("=========  ========  =======  ===  =======  ==========")
    sb.append(newLine)
    return sb.toString()
  }
  public String getLogString() {
    def newLine = System.getProperty("line.separator")
    def sb = new StringBuffer()
    def index = 0
    def presentString = null
    def makeupsString = null
    def specialtyString = null
    def evaluationString = null
    def studentidString = null
    if(this.present) {presentString="P  "} else {presentString="AB "}
    makeupsString="  ${this.getMakeups()}"
    if(this.specialty) {specialtyString="YES"} else {specialtyString="NO "}
    if(this.evaluation) {evaluationString="YES"} else {evaluationString="NO "}
    studentidString=String.format("%08d", this.studentID)
    sb.append("${this.classReportID}     ${studentidString}  ${presentString}    ${makeupsString}    ${specialtyString}   ${evaluationString}")
    sb.append(newLine)
    return sb.toString()
  }
  public String getLogStringOLD() {
    def archive = new Archive(null, null)
    def stamp = archive.getUniqueTimeStamp() 
    def sb = new StringBuffer()
    sb.append("RECORD PROCESSED ON ${stamp}> ")
    sb.append("\r\n")
    sb.append("  GLOBAL ${reportID}")
    sb.append("\r\n")
    sb.append("  GLOBAL ${className}")
    sb.append("\r\n")
    sb.append("  GLOBAL ${formPath}")
    sb.append("\r\n")
    sb.append("  GLOBAL ${formName}")
    sb.append("\r\n")
    sb.append("  classReportID: ${classReportID}")
    sb.append("\r\n")
    sb.append("  className: ${className}")
    sb.append("\r\n")
    sb.append("  studentID: ${studentID}")
    sb.append("\r\n")
    sb.append("  studentName: ${studentName}")
    sb.append("\r\n")
    sb.append("  feeType: ${feeType}")
    sb.append("\r\n")
    sb.append("  parentName: ${parentName}")
    sb.append("\r\n")
    sb.append("  signature: ${signature}")
    sb.append("\r\n")
    sb.append("  present: ${present}")
    sb.append("\r\n")
    sb.append("  makeup1: ${makeup1}")
    sb.append("\r\n")
    sb.append("  makeup2: ${makeup2}")
    sb.append("\r\n")
    sb.append("  makeup3: ${makeup3}")
    sb.append("\r\n")
    sb.append("  specialty: ${specialty}")
    sb.append("\r\n")
    sb.append("  evaluation: ${evaluation}")
    sb.append("\r\n")
    sb.append("  amountPaid: ${amountPaid}")
    sb.append("\r\n")
    return sb.toString()
  }
}

// *EOF*
